package com.example.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.math.BigDecimal;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Fruit {
    //水果名称
    private String fruitName;
    //水果单价
    private BigDecimal price;
    //购买数量
    private Integer weight;
    //折扣信息
    private Double discount;
    //水果总价钱
    private BigDecimal countPrice;

    //设置水果的总价
    public void setCountPrice() {
        if (discount!=null){
            //有折扣
            this.countPrice=price.multiply(new BigDecimal(weight)).multiply(new BigDecimal(discount));
        }else {
            //无折扣
            this.countPrice=price.multiply(new BigDecimal(weight));
        }
    }
}
